package com.gzedu.com.test;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
@Component
public class CacheTesting {
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	private Logger logger = LoggerFactory.getLogger(CacheTesting.class);

	@Test
	public void storeUserName() {
		String key = "redisTestKey";
		String value = "I am test value";

		ValueOperations<String, String> opsForValue = redisTemplate.opsForValue();

		// 数据插入测试：
		opsForValue.set(key, value);
		String valueFromRedis = opsForValue.get(key);
		logger.info("redis value after set: {}", valueFromRedis);

		// 数据删除测试：
		redisTemplate.delete(key);
		valueFromRedis = opsForValue.get(key);
		logger.info("redis value after delete: {}", valueFromRedis);
	}
}
